package com.huawei.appmarket.service.uninstallreport;

import android.app.job.JobInfo;
import android.app.job.JobInfo.Builder;
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.job.JobService;
import android.content.ComponentName;
import android.content.Context;
import androidx.annotation.RequiresApi;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.ArrayList;
import java.util.List;
import o.cfw;
import o.cvt;
import o.diu;
import o.Logger;
import o.ContentManager;
import o.ekc;
import o.euc;

@RequiresApi(api = 21)
public class UninstallReportJobService extends JobService {
    private Runnable ˊ = new Runnable(this) {
        final /* synthetic */ UninstallReportJobService ॱ;

        {
            this.ॱ = r1;
        }

        public void run() {
            if (diu.ˊ().ˎ()) {
                euc.ˊ().ॱ();
                ekc.ˋ().ˏ();
                List ॱ = ekc.ˋ().ॱ();
                if (ॱ.size() > 0) {
                    ResponseBean ॱ2 = cfw.ॱ(this.ॱ.ˊ(ॱ));
                    if (ॱ2 != null && ॱ2.getResponseCode() == 0 && ॱ2.getRtnCode_() == 0) {
                        ekc.ˋ().ˎ();
                    } else {
                        ekc.ˋ().ˊ();
                    }
                }
                euc.ˊ().ˏ();
                this.ॱ.jobFinished(this.ॱ.ˋ, false);
                return;
            }
            this.ॱ.ˎ();
            this.ॱ.jobFinished(this.ॱ.ˋ, false);
        }
    };
    private JobParameters ˋ;

    private static boolean ˋ() {
        for (JobInfo id : ((JobScheduler) ContentManager.getInstant().getContext().getSystemService("jobscheduler")).getAllPendingJobs()) {
            if (id.getId() == 100) {
                return true;
            }
        }
        return false;
    }

    public static void schedule(Context context) {
        if (!ˋ()) {
            ((JobScheduler) context.getSystemService("jobscheduler")).schedule(new Builder(100, new ComponentName(context.getPackageName(), UninstallReportJobService.class.getName())).setPersisted(true).setMinimumLatency(HwAccountConstants.CHECK_SITE_COUNTRY_DURATION).setRequiredNetworkType(1).build());
            Logger.ˎ("UninstallReportJobService", "UninstallReportJobService scheduled");
        }
    }

    public boolean onStartJob(JobParameters jobParameters) {
        Logger.ˎ("UninstallReportJobService", "UninstallReportJobService onStartJob");
        this.ˋ = jobParameters;
        new Thread(this.ˊ).start();
        return true;
    }

    public boolean onStopJob(JobParameters jobParameters) {
        return false;
    }

    private cvt ˊ(List<UninstallRecord> list) {
        cvt uninstallReportRequest = new UninstallReportRequest();
        List arrayList = new ArrayList();
        for (UninstallRecord uninstallRecord : list) {
            UninstallInfo uninstallInfo = new UninstallInfo();
            uninstallInfo.ˋ(uninstallRecord.ˋ());
            uninstallInfo.ˊ(uninstallRecord.ॱ());
            arrayList.add(uninstallInfo);
        }
        UninstallInfoJsonData uninstallInfoJsonData = new UninstallInfoJsonData();
        uninstallInfoJsonData.ˊ(arrayList);
        uninstallReportRequest.ˋ(uninstallInfoJsonData);
        return uninstallReportRequest;
    }

    private void ˎ() {
        JobScheduler jobScheduler = (JobScheduler) ContentManager.getInstant().getContext().getSystemService("jobscheduler");
        for (JobInfo id : jobScheduler.getAllPendingJobs()) {
            if (id.getId() == 100) {
                jobScheduler.cancel(100);
                return;
            }
        }
    }
}
